%this function calculates the eigenvalues of 2x2 matrices. The
%elements of each 2x2 matrix come from four different larger arrays,
%corresponding to the same row-column location

%U11, U22, U12, and U21 are four different arrays of the same size.

%L1 and L2 are two arrays of the same size of the arrays Uij. The ij-th element
%of L1 (L2) is the first (second) eigenvalue of the 2x2 matrix constructed
%with the ij-th elements of the matrices U11, U12, U21, and U22.

%Created by Ricardo Mejia-Alvarez.
%University of Illinois at Urbana-Champaign
%Urbana, IL. 05/18/2010

function [L1 , L2] = Eigenvalues_2x2(U11 , U12 , U21 , U22)

TraceU = U11 + U22;
DetU = (U11 .* U22) - (U21 .* U12);

L1 = 0.5 * (TraceU + sqrt(TraceU.^2 - 4 * DetU) );
L2 = 0.5 * (TraceU - sqrt(TraceU.^2 - 4 * DetU) );

end